package edu.corn.job.core.processor.adapter;

import edu.corn.job.core.context.JobRunningContext;
import edu.corn.job.core.engine.JobEngine;
import edu.corn.job.core.processor.AbstractJobProcessor;

public class PhaseJobAdapter extends AbstractJobAdapter {

    public PhaseJobAdapter(AbstractJobProcessor processor, JobEngine jobEngine) {
        super(processor, jobEngine);
    }


    @Override
    public boolean doJobInternal(JobRunningContext context) {
        AbstractJobProcessor phaseJob = getJobProcessor();
        try {
            phaseJob.execute(context);
        } catch (Throwable e) {
            // 尝试让job自己处理异常。
            if (!phaseJob.handleException(e, context)) {
                throw e;
            }
        }
        return true;
    }
}
